﻿var Global_WorkFlow_MeasureType = 0; //计量类型：施工计量
var WorksMeasureSettings = {
    _index: 0, //tab标签默认选中索引
    _dialogIsClose: 0,
    _htdid: 0, //标段id
    _sessionId: 0, //计量清单id
    _measurephaseId: 0, //保存从计量期管理传过来的计量期id
    _htdCode: "", //标段号
    _jlqCode:"",//计量期号  如： 第1期
    isUnAudited: true,//流程是否未批复
    tabLinkBindClick: function () {//tab标签的点击事件绑定
        $(".headerCenter a").bind("click", function () {
            $(".headerCenter a").eq(WorksMeasureSettings._index).removeClass("selected");
            $(this).addClass("selected");
            $(".MeasuerContainer").eq(WorksMeasureSettings._index).hide(); //本次点击之前的那个a
            WorksMeasureSettings._index = $(this).attr("index");
            $(".MeasuerContainer").eq(WorksMeasureSettings._index).show();
            WorksMeasureSettings.loadDivContentHtml();
        });
    },
    TabBind_dblclick: function () {
        $(".headerCenter a").dblclick(function () {
            $(".headerCenter a").eq(WorksMeasureSettings._index).removeClass("selected");
            $(this).addClass("selected");
            $(".MeasuerContainer").eq(WorksMeasureSettings._index).hide(); //本次点击之前的那个a
            WorksMeasureSettings._index = $(this).attr("index");
            $(".MeasuerContainer").eq(WorksMeasureSettings._index).show();

            var url = $(this).attr("load_url");
            var $content = $(".MeasuerContainer").eq(WorksMeasureSettings._index);
            if (url == "") return false;
            $content.html("").load(url + "?isSum=1", function () {
                if (WorksMeasureSettings._index == 0) {
                    WorksMeasureSettings._calcMergeCellH();
                }
            });

        });
    },
    loadDivContentHtml: function () {//控制加载以及显隐tab标签对应的内容div
        var $obj = $(".headerCenter a").eq(WorksMeasureSettings._index);
        var $content = $(".MeasuerContainer").eq(WorksMeasureSettings._index);
        var url = $obj.attr("load_url");
        if (WorksMeasureSettings._index == 0) {
            $content.html("").load(url + "?isSum=1", function () {
                if (WorksMeasureSettings._index == 0)
                    WorksMeasureSettings._calcMergeCellH();
            });

        } else {
            if (url == "") return false;
            if ($.trim($content.html()) == "") {
                $content.html("").load(url, function () {
                    if (WorksMeasureSettings._index == 0)
                        WorksMeasureSettings._calcMergeCellH();
                });
            }
        }
    },
    _calcMergeCellH: function () {//计算合并后单元格的高度
        //对于合并行单元格的文本设置垂直居中
        $("#tbSumData tbody td[rowspan]").each(function () {
            var rows = $(this).attr("rowspan");
            $(this).css("line-height", (rows * 28) + "px");
        });
        //小计行加背景
        $("#tbSumData tbody td[bgflag='4']").each(function () {
            var tr = $(this).parent();
            tr.addClass("tr-bg");
        });
        //固定汇总计量数据的表头 并赋予原有表的宽度
        $("#tbSumData").prev().children("thead").html($("#tbSumData thead").html());
        $("#tbSumData").prev().width($("#tbSumData").width() + 1);
        WorksMeasureSettings._clearZero();
    },
    _clearZero: function () {//单元格为0，都处理为空
        $("#tbSumData tbody td[class='tr']").each(function () {
            if ($.trim($(this).html()) == "0.00") {
                $(this).html("");
            }
        });
    },
    workflowCurrentState: function () { //工作流程当前状态（0为可操作，1为只读）
        if ($("#hidCurType").val() == "1")
            return false; //表示当前用户不能操作只能查看
        return true;
    },
    dialogCloseCallback: function () {
        var IsClose_State = false;
        if (WorksMeasureSettings.dialogIsClose == 1) {
            IsClose_State = true;
        }
        else {
            if (WorksMeasureSettings._htdid == 0 || WorksMeasureSettings._sessionId == 0) {
                alertMsg.confirm("您确定不进行计量，关闭当前页吗？", {
                    okCall: function () {
                        IsClose_State = true;
                        WorksMeasureSettings.dialogIsClose = 1;
                        $.pdialog.closeCurrent();
                        navTab.closeCurrentTab();
                    }
                })
            }
            else {
                IsClose_State = true;
            }
        }
        return IsClose_State;
    },
    openDialogSelectHtdAndMeasure: function () {//页面加载时弹出窗体选择标段及计量期
        if (WorksMeasureSettings._measurephaseId == 0 && (WorksMeasureSettings._htdid == 0 || WorksMeasureSettings._sessionId == 0)) {
            $.pdialog.open("/WorkFlow/WorksMeasure/SelectHtdAndMeasure", "rel_WorkFlow_WorksMeasure_SelectHtdAndMeasure", "选择标段及计量期", { "width": "400", "height": "290", "mask": "true", "close": WorksMeasureSettings.dialogCloseCallback });
        } else if (WorksMeasureSettings._measurephaseId != 0 && WorksMeasureSettings._htdid != 0) {
            $.ajax({
                url: "/WorkFlow/WorksMeasure/SaveSessionWorkFlowIns",
                type: "post",
                dataType: "json",
                data: { "segmentID": WorksMeasureSettings._htdid, "measureID": WorksMeasureSettings._measurephaseId,
                    "WorkflowId": $("#WorkflowId_Start").val(),
                    "WorktaskId": $("#WorktaskId_Start").val(),
                    "WorkflowInsId": $("#WorkflowInsId_Start").val(),
                    "WorktaskInsId": $("#WorktaskInsId_Start").val()
                },
                success: function (json) {
                    if ("forward" == json.callbackType) {
                        navTab.reload(json.forwardUrl);
                        $("#BaseInfo_MeasurePhase_Index").trigger("reloadGrid"); //计量期列表重新加载JqGrid;
                        $("#Claimed_Home_Index").trigger("reloadGrid"); //首页重新加载JqGrid;
                    }
                }
            });
        }
    },
    openReportNavTab: function () {
        navTab.openTab("CALReportExport", "/Report/ConstructionReport/ExprotAllExl/?htdId=" + WorksMeasureSettings._htdid + "&sessionId=" + WorksMeasureSettings._sessionId, { title: "施工报表" });
    },
    SelectDefaultIdeas: function () {
        $("a.clsIdeas").bind("click", function () {
            $("#WorksMeasure_Ideas").text($(this).text());
        });

    },
    AttachOptionKeyValue: "uploaderoption=\"{'MoudleID':10005195,'ToSelectIDs':[{0}],'ToDeleteIDs':[{1}],'BizDeleteURL':'/Common/Attachment/Delete','BizSaveUrl':'/Common/Attachment/BatchAdd','BizType':'{2}','BizID':{3},'isDelete':{4},'dirWhere':'{5}'}\"",
    AttachOption: "{'MoudleID':10005195,'ToSelectIDs':[{0}],'ToDeleteIDs':[{1}],'BizDeleteURL':'/Common/Attachment/Delete','BizSaveUrl':'/Common/Attachment/BatchAdd','BizType':'{2}','BizID':{3},'isDelete':{4},'dirWhere':'{5}'}",
    openAttachDialog: function (objId) {
        $.pdialog.open("/Common/UploaderFile/Uploader?id=" + objId, "UploaderFileIndex", "附件管理", { width: "800", height: "600", mask: "true" });
    }
}
